<template>
  <v-app id="inspire">
    <v-content>
      <v-container >
        <h1 style="text-align: center">My Contributions</h1>
        <displayList
          :_title="contributionTitle"
          :_items="myContribution"
          :_item-per-page="4"
          @wantToEdit="update"
          @wantToRebuttal="rebuttal"
          @wantToNotRebuttal="notRebuttal"
        >
        </displayList>

        <h1 style="text-align: center">My Results</h1>
        <displayList
          :_items="iContributed"
          :_item-per-page="4"
        >
        </displayList>
        <side-bar></side-bar>
      </v-container>
    </v-content>
  </v-app>
</template>

<script>
import store from '../../store'
import DisplayList from '../DisplayList'
import SideBar from './SideBar'
export default {
  name: 'MyContributionDashboard',
  components: {
    SideBar,
    DisplayList
  },
  data () {
    const generateMyContribution = _ => {
      const contributions = []
      this.$axios.post('/meetingIContributed', store.state.userName)
        .then(resp => {
          if (resp != null) {
            var response = resp.data
            response.forEach((contribution, index) => {
              contributions.push({
                // identity : "Author",
                // contributor : contribution.contributor,
                abbrName: contribution.meetingFullName,
                MeetingFullName: contribution.meetingFullName,
                FileTitle: contribution.fileTitle,
                FileAbstract: contribution.fileAbstract,
                contributor: contribution.contributor,
                meetingStatus: contribution.meetingStatus,
                contributionStatus: contribution.status
                // topics: contribution.topics
              })
            })
            return contributions
          } else return null
        })
        .catch(error => {
          console.log(error)
        })
      return contributions
    }
    const generateContributedConference = _ => {
      const conferences = []
      this.$axios.post('/myResults', store.state.userName)
        .then(resp => {
          if (resp != null) {
            var response = resp.data
            response.forEach((mark, index) => {
              conferences.push({
                // identity : "Author",
                // contributor : contribution.contributor,
                title: mark.title,
                marks: mark.marks,
                comments: mark.comments,
                confidences: mark.confidences,
                abbrName: mark.meetingFullName,
                passed: mark.passed
              })
            })
            return conferences
          } else return null
        })
        .catch(error => {
          console.log(error)
        })
      return conferences
    }
    return {
      myContribution: generateMyContribution(),
      contributionTitle: 'Contribution',
      iContributed: generateContributedConference()
    }
  },
  methods: {
    update (item) {
      // this.$router.replace('/workspace/myContribution/'+item.FileTitle)
      this.$router.push({
        path: '/workspace/myContribution/' + item.MeetingFullName,
        query: {
          fileTitle: item.FileTitle
          // topics: item.topics
        }
      })
    },
    rebuttal (item) {
      // this.$router.replace('/workspace/myContribution/'+item.FileTitle)
      this.$router.push({
        path: '/rebuttal/' + item.MeetingFullName,
        query: {
          fileTitle: item.FileTitle
          // topics: item.topics
        }
      })
    },
    notRebuttal (item) {
      this.$axios.post('/refuseToRebuttal', {
        contributor: store.state.userName,
        meetingFullName: item.MeetingFullName,
        title: item.FileTitle,
        comments: null
      })
        .then(resp => {
          if (resp.status === 200) {
            this.text = '成功确认不反驳'
            this.snackbar = true
            location.reload()
          } else {
            this.text = '未知原因失败'
            this.snackbar = true
          }
        })
        .catch(error => {
          console.log(error)
        })
    }
  }
}
</script>
